<template>
	<view>
		<view class="top">
			交友最怕遇到什么？不真诚！<br>
			交友过程中，谁都怕遇到假信息、骗子、海王、目的不纯者，对自身伤害极大，浪费大好青春！<br> 想尽可能的过滤掉不真诚的人吗？ <br>
			有！通过建立真诚指数，能最大程度过滤掉不真诚之人！
			请不要嫌麻烦，试想，完全陌生的两个人，你突然要闯入他/她的生活，没点真诚心，谁敢见你。
		</view>
		<view class="section">
			<view class="title">
				提升方式一：邀请真诚认证人
			</view>
			<view class="text">
				根据邀请人数，提升真诚指数，每邀请1人提升5点真诚指数。
			</view>
			<button class="btn" @click="goToInvite">
				去邀请
			</button>
		</view>
		<view class="section">
			<view class="title">
				提升方式二：缴纳真诚保证金
			</view>
			<view class="text">
				根据个人情况向平台缴纳真诚保证金，保证金可随时申请退还。平台会收取1%的手续费用。每100元钱提升2点真诚指数。
			</view>
			<view class="btn" @click="goToVip">
				去缴纳
			</view>
		</view>
		<view class="section">
			<view class="title">
				提升方式三：提交证明材料
			</view>
			<uni-section title="车辆证明" type='square'>
				<view class="example-body">
					<imgUpload class="upload" :max="1" :action="`${uploadUrl}${state}/`" v-model="carList"
						@uploadSuccess="res=>uploadSuccess(res,'car')" @uploadFail="res=>uploadFail(res,'car')"
						@imgDelete="res=>imgDelete(res,'car')" :headers="{'Authorization':token}">

					</imgUpload>
				</view>
			</uni-section>
			<uni-section title="房屋证明" type='square'>
				<view class="example-body">
					<imgUpload class="upload" :max="1" :action="`${uploadUrl}${state}/`" v-model="houseList"
						@uploadSuccess="res=>uploadSuccess(res,'house')" @uploadFail="res=>uploadFail(res,'house')"
						@imgDelete="res=>imgDelete(res,'house')" :headers="{'Authorization':token}">

					</imgUpload>
				</view>
			</uni-section>
			<uni-section title="学历证明" type='square'>
				<view class="example-body">
					<imgUpload class="upload" :max="1" :action="`${uploadUrl}${state}/`" v-model="educationList"
						@uploadSuccess="res=>uploadSuccess(res,'education')"
						@uploadFail="res=>uploadFail(res,'education')" @imgDelete="res=>imgDelete(res,'education')"
						:headers="{'Authorization':token}">

					</imgUpload>
				</view>
			</uni-section>
			<uni-section title="工作/收入证明" type='square'>
				<view class="example-body">
					<imgUpload class="upload" :max="1" :action="`${uploadUrl}${state}/`" v-model="workList"
						@uploadSuccess="res=>uploadSuccess(res,'work')" @uploadFail="res=>uploadFail(res,'work')"
						@imgDelete="res=>imgDelete(res,'work')" :headers="{'Authorization':token}">

					</imgUpload>
				</view>
			</uni-section>
			<uni-section title="其他" type='square'>
				<view class="example-body">
					<imgUpload class="upload" :max="1" :action="`${uploadUrl}${state}/`" v-model="otherList"
						@uploadSuccess="res=>uploadSuccess(res,'other')" @uploadFail="res=>uploadFail(res,'other')"
						@imgDelete="res=>imgDelete(res,'other')" :headers="{'Authorization':token}">

					</imgUpload>
				</view>
			</uni-section>
			<view class="btn" @click="goUpload">
				去上传
			</view>
			<view class="desc">
				<span style="color:#FC9380">证明规则说明</span><br>
				1.您需要先完成实名认证，才能审核通过真诚指数证明材料，提交的证明材料无认证费用。<br>
				2.您提交的证明材料必须真实可靠，禁止伪造、P图、遮挡等行为，否则进行
				封号处理。您的材料一经审核通过（含实名认证），最高可获得60分真诚指
				数，其中：实名认证10分，车辆证明10分，房屋证明10分，学历证明10分，
				工作/收入证明10分，其他证明10分。<br>
				3.您提交的证明材料可进行加水印处理，如：仅作为缘诉真诚指数认证使用。<br>
				4.您提交的证明材料越全，获得的真诚指数越高，越容易吸引别人与您沟通交友，越容易高质量脱单。<br>
				5.证明材料类型说明：<br>
				（1）车辆证明：请提供您名下机动车登记证书或车辆行驶证。<br>
				（2）房屋证明：请提供您名下不动产权证书/房屋所有权证；若房屋不在您名下，请联系客服提供户口本及户主名下的不动产权证书。<br>
				（3）学历证明：请提供毕业证书或学信网证明。<br>
				（4）工作/收入证明：请提供正式的工作证明、银行流水、个税证明、工作证等或其他可以证明您工作或收入的其他证明材料。<br>
				6.您提交的证明材料，本平台会严格保密，不会向任何人透露。下列情况除外:<br>
				　　（1）违反相关法律法规或本平台服务协议规定；<br>
				　　（2）按照主管部门的要求,有必要向相关法律部门提供备案的内容；<br>
				　　（3）被侵害的第三人提出合法的权利主张；<br>
				　　（4）为维护用户或本平台的合法权益的需要；<br>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		url,
		request,
		login
	} from '@/service/api.js'
	import imgUpload from '@/components/htz-image-upload/htz-image-upload.vue'
	export default {
		data() {
			return {
				token: `Bearer ${uni.getStorageSync('auth')}`,
				state: 0,
				uploadUrl: url.upload,
				imgList: [],
				carList: [],
				houseList: [],
				educationList: [],
				workList: [],
				otherList: [],
				// localDocs: ['请选择', '车辆证明', '房屋证明', '学历证明', '工作/收入证明', '其他']
			};
		},

		onShow() {
			this.getInfo()
		},
		components: {
			imgUpload
		},
		onShareAppMessage(res) {
			if (res.from === 'button') { // 来自页面内分享按钮
				console.log(res.target)
			}
			return {
				title: '我正在使用缘诉交友，快来和我成为好友吧~',
				path: `/pages/tabBar/Home/Home`
			}
		},
		methods: {
			getInfo() {
				request(url.getReliable, 'GET').then(res => {
					console.log(res)
					if (res.status === 200) {
						const data = res.data
						this.carList = data.car ? [data.car] : []
						this.houseList = data.house ? [data.house] : []
						this.educationList = data.education ? [data.education] : []
						this.workList = data.income ? [data.income] : []
						this.otherList = data.other ? [data.other] : []
					}
				}).catch(err => {
					uni.showToast({
						title: err.msg
					})
				})
			},
			goToInvite() {
				request(url.getInviteCode, 'GET').then(res => {
					if (res.status === 200) {
						uni.showModal({
							cancelText: '取消',
							confirmText: '复制链接',
							success: () => {
								const clipboardObj = navigator.clipboard;
								clipboardObj.writeText(
									`https://app.52yinyuan.com/pages/login/login?inviteCode=${res.data}`
								);
							},
							content: `如果您身边有单身的朋友还没有遇到心动对象，请把他们都邀请来诉缘，这样诉缘的资源也会越来越多。单丝不成线，独木不成林，一人难成事，齐心可脱单。邀请成功后，您将获得100缘分值并且提升5点真诚指数/位，您的邀请码是${res.data}。链接：https://app.52yinyuan.com/pages/login/login?code=${res.data}`
						})
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				}).catch(err => {
					uni.showToast({
						title: err.msg,
						icon: 'none'
					})
				})
			},
			goToVip() {
				uni.navigateTo({
					url: '/pages/membership/membership'
				})
			},
			goToShare() {
				uni.share({
					provider: "weixin",
					scene: "WXSceneSession",
					type: 1,
					summary: "我正在使用缘诉交友，快来和我成为好友吧~",
					success: function(res) {
						console.log("success:" + JSON.stringify(res));
					},
					fail: function(err) {
						console.log("fail:" + JSON.stringify(err));
					}
				});
			},
			uploadSuccess(res, type) {
				console.log(type)
				let list = [];
				switch (type) {
					case 'car':
						list = this.carList
						break;
					case 'house':
						list = this.houseList
						break;
					case 'work':
						list = this.workList
						break;
					case 'education':
						list = this.educationList
						break;
					case 'other':
						list = this.otherList
						break;
					default:
						break;
				}
				if (res.statusCode === 200) {
					const result = JSON.parse(res.data)
					list.push(result.data)
					console.log(result)
				}
			},
			uploadFail(e) {
				uni.showToast({
					title: '错误',
					text: '上传图片失败'
				})
			},
			imgDelete(e, type) {
				let list = [];
				switch (type) {
					case 'car':
						list = this.carList
						break;
					case 'house':
						list = this.houseList
						break;
					case 'work':
						list = this.workList
						break;
					case 'education':
						list = this.educationList
						break;
					case 'other':
						list = this.otherList
						break;
					default:
						break;
				}
				list = [];
			},
			goUpload() {
				let param = {
					car: this.carList[0] || '',
					house: this.houseList[0] || '',
					education: this.educationList[0] || '',
					income: this.workList[0] || '',
					other: this.otherList[0] || ''
				}
				request(url.uploadReliable, 'post', param).then(res => {
					if (res.status === 200) {
						uni.showToast({
							title: '上传成功',
						})
					} else {
						uni.showToast({
							title: res.msg,
							icon: "error"
						})
					}
				}).catch(err => {
					uni.showToast({
						title: err.msg,
						icon: "error"
					})
				})
			},
		}
	}
</script>

<style lang="less">
	* {
		box-sizing: border-box;
	}

	.top {
		width: 100%;
		padding: 12px 18px;
		background: linear-gradient(-41deg, rgba(49, 104, 174, 0.57), rgba(145, 83, 188, 0.57));
		font-size: 13px;
		color: #FFFFFF;
		line-height: 23px;
	}

	.section {
		margin-top: 10px;
		padding: 18px;
		width: 100%;
		background-color: #fff;

		.title {
			font-size: 15px;
			color: #4F4F4F;
			line-height: 23px;
		}

		.text {
			font-size: 8px;
			color: #888888;
			line-height: 23px;
		}

		.btn {
			margin: auto;
			margin-top: 12px;
			width: 256px;
			height: 35px;
			background: #FC9380;
			border-radius: 5px;
			font-size: 17px;
			color: #FFFFFF;
			line-height: 23px;
			display: flex;
			align-items: center;
			justify-content: center;
		}

		.select {
			/deep/ .uni-input {
				box-sizing: content-box;
				color: #4D4D4D;
			}

			color :#4D4D4D;
			display: flex;
			justify-content: space-between;
			align-items: center;
			border-top:1px solid #dcdcdc;
			border-bottom:1px solid #dcdcdc;
		}

		.desc {
			color: #999;
			line-height: 23px;
			margin-top: 20px;
			font-size: 13px;
		}

	}
</style>
